using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Tables;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
	[CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.administrators})]
	
	public class AccountsController : BaseController 
	{
		private readonly IAccountsServer _iAccountsServer;

		public AccountsController (IAccountsServer iAccountsServer)
		{
			_iAccountsServer = iAccountsServer;
		}
		
		/// <summary>
		/// 详情
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<IActionResult> Detail(int id)
		{
			return Send(await _iAccountsServer.DetailAsync(id));
		}
		
		/// <summary>
		/// 分页
		/// </summary>
		/// <param name="page">当前是第几页</param>
		/// <param name="limit">一页有多少条数据</param>
		/// <param name="key">要查询的关键字</param>
		/// <returns></returns>
		[HttpGet]
		public async Task<IActionResult> Pagination(int page,int limit,string? key)
		{
			return Send(await _iAccountsServer.PaginationAsync(page,limit,key));
		}
	}
}
	